/**
 * 个人中心模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	
	//交易状态
	$(document).on("click",".btn-group .btn",function(){
		if(!$(this).parent().hasClass("open")){$(this).parent().addClass("open");}else{$(this).parent().removeClass("open")}
		$(document).on("click",function(event){
			var _target=$(event.target).parents();
			if(!_target.hasClass("btn-group")){
				  $(".btn-group").removeClass("open");				  
			}else{_target.siblings(".btn-group").removeClass("open");}	
		});
	});

	$(document).on("click",".btnFile",function(){
		$(this).siblings("input:file").click();	
	});
	$(document).on("click",".ldh-changeBtn",function(){
		var box=$(this).parents(".ldh-securityInfo").find(".ldh-securityInfo-changebox");
		if(box.hasClass("on")){
			box.removeClass("on");
		}else{$(".ldh-securityInfo-changebox").removeClass("on");box.addClass("on");}
		
	});
	
	//添加地址显示、隐藏
	/*$(document).on("click",".ldh-myAdress-new button",function(){
		$(this).parent(".ldh-myAdress-new").siblings(".ldh-myAdress-edit").toggle();	
	});*/
	//给商家留言
	$(".ldh-gessage-bbs .textarea").focus(function(){
		$(this).addClass("textarea-focus");	
	});
	$(".ldh-gessage-bbs .textarea").blur(function(){
		$(this).removeClass("textarea-focus");	
	});
	
	
	//上传照片框隐藏
	exports.mypicHide=function(){
		$(".ldh-mypicture-bg").hide();	
	};
	//上传照片框出现
	exports.mypicShow=function(){
		
		var htmlStr="";
		

		htmlStr += '<div class="ldh-mypic-title"><h3>上传头像</h3></div>';
		htmlStr += '<div class="ldh-mypic-cont clearfix">';
		htmlStr += '<div class="ldh-mypic-contL" id="ucenter_preview_iconUrl_div"><div class="ldh-personalInfo clearfix" style="display:none;" id="upload_loading_upLoadFileButton"><img src="'+ctx+'/v1/img/upload_loading.gif" alt="头像"></div><span id="upLoadFileButton"></span></div>';
		htmlStr += '<div class="ldh-mypic-contR">';
		htmlStr += '<dl>';
		htmlStr += '<dt><p>拖拽或缩放虚线框，生成自己满意的头像</p></dt>';
		htmlStr += '<dd id="preview-pane_90" >';
		htmlStr += '<p class="mypic_90"><img id="preview_iconUrl_90" width="90px" height="90px" class="jcrop-preview" src="'+ctx+'/v1/img/category_f.png" /></p>';
		htmlStr += '<p class="text-center">90px&nbsp;&nbsp;x&nbsp;&nbsp;90px</p>';
		htmlStr += '</dd>';
		htmlStr += '<dd id="preview-pane_50" >';
		htmlStr += '<p class="mypic_50"><img id="preview_iconUrl_50" width="50px" height="50px" class="jcrop-preview" src="'+ctx+'/v1/img/category_f.png" /></p>';
		htmlStr += '<p class="text-center">50px&nbsp;&nbsp;x&nbsp;&nbsp;50px</p>';
		htmlStr += '</dd>';
		htmlStr += '<dd id="preview-pane_30" >';
		htmlStr += '<p class="mypic_30"><img id="preview_iconUrl_30" width="30px" height="30px" class="jcrop-preview" src="'+ctx+'/v1/img/category_f.png" /></p>';
		htmlStr += '<p class="text-center">30px&nbsp;&nbsp;x&nbsp;&nbsp;30px</p>';
		htmlStr += '</dd>';
		htmlStr += '</dl>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="ldh-mypic-btn clearfix">';
		htmlStr += '<button class="btn-main fl-right" type="button" onclick="$ldh_user.saveUploadHeadImage(this)">保存并关闭</button>';
		htmlStr += '</div>';
		htmlStr += '<div class="ldh-mypic-close" onClick="$ldh_user.mypicHide()"></div>';
        
		$(".ldh-mypicture").html(htmlStr);
		$("#x_upLoadFileButton").val("");
		$("#y_upLoadFileButton").val("");
		$("#width_upLoadFileButton").val("");
		$("#height_upLoadFileButton").val("");
		upload.ldh_upload("upLoadFileButton","/user/info","uploadHeadImageCallBack");

		$(".ldh-mypicture-bg").show();	
		
	};
	
	//保存裁剪后的头像
	exports.saveUploadHeadImage=function(obj){
		$(obj).html("正在保存...");
		$(obj).attr("disabled","disabled");
		var frame_url=window.location.protocol +"//" + window.location.host+ctx+"/frame.jsp?callBack=saveUploadHeadImageCallBack";
		document.getElementById("form_upLoadFileButton").action=fileUploadUrl+"?x="+$("#x_upLoadFileButton").val()+"&y="+$("#y_upLoadFileButton").val()+"&width="+$("#width_upLoadFileButton").val()+"&height="+$("#height_upLoadFileButton").val()+"&img_width="+$(".jcrop-holder img:eq(1)").width()+"&img_height="+$(".jcrop-holder img:eq(1)").height()+"&path=/user/info&rename=true&overwrite=true&url="+frame_url;
		document.getElementById("form_upLoadFileButton").target="_upload_frame_form_upLoadFileButton";
		document.getElementById("form_upLoadFileButton").submit();
	};
	
	
	//保存裁剪后的头像回调函数
	saveUploadHeadImageCallBack=function(dataObj){
		
		var dataPath = "";
		if(dataObj.code == "1"){
			for(var i=0;i<dataObj.files.length;i++){
				if(dataObj.files[i].repCode=="1"){
					dataPath = dataObj.files[i].path;
					$("#ucenter_iconUrl").val(dataPath);
					$("#ucenter_iconUrl").attr("src", fileOpenUrl + dataPath);
					exports.mypicHide();
				}else{
					
				}
			}
			
			
		}else{
			//上传失败
			$(obj).html("保存并关闭");
			$(obj).attr("disabled",false);
		}
		
	};
	
	
	var pageSize=10;
	
	require("../../custom/base/component-core.js");
	
	require("../../custom/base/component-page.js");
	
	require("../../custom/base/component-md5.js");
	
	var validate = require("../../custom/base/component-validate.js");
	
	var base = require("../../custom/base/component-base.js");
	
	base.init(base);
		
	var async = require("../../custom/base/component-async.js");
	
	var head=require("../../custom/head/module-head.js");
	
	head.init(head);
	
	var upload=require("../../custom/base/component-upload.js");
	
	var history=require("../../custom/base/component-history.js");
	
	//设置订单状态
	exports.setOrderStatusId=function(orderStatusId,orderStatusName){
		
		this.orderStatusId=orderStatusId;
		
		$("#orderStatusName").html(orderStatusName);
		
		$(".btn-group").removeClass("open");
		
		exports.setOrderCurrentPage(1);
		
		exports.getMyOrder();
	};
	
	//获取订单状态
	exports.getOrderStatusId=function(){
		
		return this.orderStatusId==null?"":this.orderStatusId;
		
	};
	
	//初始化函数
	exports.init=function(m){
		
		
		window.$ldh_user=m;
		
		base.setFromPage("userIndex");
		
		var userId=$("#session_userid").val();
		
		if(!validate.isNull(userId)){
			
			base.hasLoginShow(userId,$("#session_username").val(),$("#session_iconurl").val());
			
		}else{
			
			base.loginShow();
		}
	
		//exports.getMyOrder();
		
		document.title="云便利商店-个人中心";
		
		//history.addHis(this,arguments);
		
	};
	
	//设置订单列表页码
	exports.setOrderCurrentPage=function(orderCurrentPage){
		
		this.orderCurrentPage=orderCurrentPage;
		
	};
	
	//获取订单列表页码
	exports.getOrderCurrentPage=function(){
		
		return this.orderCurrentPage==null?1:this.orderCurrentPage;
		
	};
	
	
	//查询我的订单
	exports.getMyOrder=function(){
		
		history.addHis(this,arguments);
		
		$(".ldh-myCenterR").hide();
		
		$("#ldh-myOrderList").show();
		
		$(".ldh-myCenter-btm li a").css("color","#9a8072");
		
		$(".ldh-index-myorder").css("color","#ed5d3a");
		
		
		var params = {
				userId : $("#session_userid").val(),
				orderStatusId:exports.getOrderStatusId(),
				pageSize : pageSize,
				currentPage : exports.getOrderCurrentPage()
		};
		
		$("#orderList tbody").remove();
		
		$("#myorder-ldh-waiting").show();
		
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Order/getMyOrderGoods.do", params));
						
						$("#myorder-ldh-waiting").hide();
						
						if(!base.validateLoginStatus(data)){
							
							
							
							return;
						}
						
						
						if(data["code"]==1){
							
							var htmlStr="";
							
							
							
							for(var i=0;i<data["data"].length;i++){

											htmlStr += '<tbody> ';
											htmlStr += ' <tr>';
											htmlStr += '<td class="text-left ldh-order-storeinfo" colspan="7"><span>订单号：<b>'+data["data"][i]["orderId"]+'</b></span><span>创建时间：<b>'+data["data"][i]["orderTime"]+'</b></span><span>商户：<b><a href=javascript:$ldh_base.jumpToShopIndex("'+data["data"][i]["shopId"]+'")>'+data["data"][i]["shopName"]+'</a></b></span><span>电话：<b>'+data["data"][i]["phone"]+'</b></span><span>配送方式：<b>'+data["data"][i]["deliveryName"]+'</b></span><br><br><span style="float:right;color:#ed5d3a;"><b>'+data["data"][i]["orderTimeOut"]+'</b></span></td>';
											htmlStr += '</tr>';
											htmlStr += '<tr>';
											htmlStr += '<td colspan="3" class="order_product_first">';
											htmlStr += '<table>';
											htmlStr += '<colgroup >';
											htmlStr += '<col width="16%" />';
											htmlStr += '<col width="44%" />';
											htmlStr += '<col width="24%" /> ';
											htmlStr += '<col width="16%" />';
											htmlStr += '</colgroup>';
											htmlStr += '<tbody>  ';
											for(var j=0;j<data["data"][i]["goods"].length;j++){	
												
												var picDefault=data["data"][i]["goods"][j]["picDefault"];
												
												
												if(validate.isNull(picDefault)){
													
													picDefault = ctx+"/v1/img/default_234_220.png";

												}else{
													
													picDefault=fileOpenUrl+picDefault;

												}
												
												
												htmlStr += '<tr>';
												//htmlStr += '<td class="text-center"><div class="ldh-orderpic"><a class="pic" href="####"><img src="'+picDefault+'" alt="查看宝贝详情" /></a></div></td>';
												//htmlStr += '<td class="text-left"><a class="text" href="#" target="_blank">'+data["data"][i]["goods"][j]["merchandiseName"]+'</a></td>';
												htmlStr += '<td class="text-center"><div class="ldh-orderpic"><img src="'+picDefault+'" alt="查看宝贝详情" /></div></td>';
												htmlStr += '<td class="text-left">'+data["data"][i]["goods"][j]["merchandiseName"]+'</td>';
												htmlStr += '<td>¥'+data["data"][i]["goods"][j]["price"]+'</td>';
												htmlStr += '<td>'+data["data"][i]["goods"][j]["nums"]+'</td>';
												htmlStr += '</tr>';
											}
											htmlStr += '</tbody>';
											htmlStr += '</table>';
											htmlStr += ' </td>';
											htmlStr += '<td style="color:#ed5d3a;"><p class="order_money">¥'+Number(data["data"][i]["totalAmount"]).toFixed(2)+'</p>';
											if(data["data"][i]["deliveryAmount"]>0){
												htmlStr += '<p class="yun_money main_color">(包含配送费：'+Number(data["data"][i]["deliveryAmount"]).toFixed(2)+'元)</p>';
											}
											htmlStr += '</td>';
											htmlStr += '<td><p>'+data["data"][i]["paymentName"]+'</p></td>';
											if(data["data"][i]["orderStatus"]=="交易关闭"){
												htmlStr += '<td style="color:#ed5d3a;"><p>'+data["data"][i]["orderStatus"]+'</p>';
											}else{
												htmlStr += '<td style="color:#339933;"><p>'+data["data"][i]["orderStatus"]+'</p>';
											}
											
											//htmlStr += '<p><a href="'+ctx+'/orderdetails.jsp?orderId='+data["data"][i]["orderId"]+'">详情</a></p> ';
											htmlStr += '</td>';
											htmlStr += '<td><p><a href=javascript:$ldh_user.getOrderDetail("'+data["data"][i]["orderId"]+'")>详情</a></p></td>';
											htmlStr += '</tr>';
											htmlStr += '</tbody>';
		                      
		                      
								
							}
						
							if(validate.isNull(htmlStr)){
								
								$("#myorder-no-data-tip").show();
								
								$('#myorder-footPage').html("");
								
							}else{
								
								$("#myorder-no-data-tip").hide();
								
								$("#orderList thead").after(htmlStr);
								
								$('#myorder-footPage').ldh_pagination_shoplist(data["pageSize"],data["currentPage"],data["totals"],data["pages"],{  
									 
									 changePageCallback:function(pageSize,page){  
										
										 exports.setOrderCurrentPage(page);
										 exports.getMyOrder();
									 },
									 changePageSizeCallBack:function(pageSize){
									 } 
						         }); 
							}
							
							
 
						}else if(data["code"]=="-10001"){
							
							alert(data["message"]);
							
						}
						
						
						
		}))().start();
		
	};
	
	//订单详情
	exports.getOrderDetail=function(orderId){
		
		history.addHis(this,arguments);
		
		$(".ldh-myCenterR").hide();
		
		$("#ldh-myOrderDetail").show();
		
		$("#order_detail_div").hide();
		
		$("#order_detail_loading").show();
		
		
		var params = {
				orderId:orderId
		};
		
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/Order/getOrder.do", params));
						
						
						if(data["code"]==1){
							
							//订单操作
							var orderButtonHtmlStr="";
							
							if(data.allowPayOrder=="1"){
								orderButtonHtmlStr += '<button type="button" onClick=$ldh_user.goPay("'+data["orderId"]+'","'+data["totalAmount"]+'") class="btn-green">去付款</button>';
							}
							
							if(data.allowRefuse=="1"){
								orderButtonHtmlStr += '<button type="button" class="btn-main" onClick=$ldh_user.rejectReason("refuse","拒绝收货","4","'+data.orderId+'")>拒绝收货</button>';
							}else{
								if(data.allowCancelOrder=="1"){
									orderButtonHtmlStr += '<button type="button" class="btn-main" onClick=$ldh_user.rejectReason("cancel","取消订单","2","'+data.orderId+'")>取消</button>';
								}
							}
							
							if(data.allowRemind=="1"){
								orderButtonHtmlStr += '<button type="button" class="btn-green" onClick=$ldh_user.remindToShop("'+data.orderId+'","是否确认提醒商家发货？")>提醒商家发货</button>';
							}
							
							if(data.allowApply=="1"){
								orderButtonHtmlStr += '<button type="button" class="btn-main" onClick=$ldh_user.rejectReason("apply","客服介入","6","'+data.orderId+'")>申请客服介入</button>';
							}
							
							if(data.allowFinishOrder=="1"){
								orderButtonHtmlStr += '<button type="button" class="btn-main" onClick=$ldh_user.processOrder("","5","'+data.orderId+'","是否确认收货？")>确认收货</button>';
							}
							
							$("#order_detail_btn").html(orderButtonHtmlStr);
				              
							//订单状态
			/*				var orderstatushtmlStr = "";

								if(data.orderDate!=""){
								
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titlea">提交订单</p>';
								orderstatushtmlStr += '<p>'+data.orderDate+'</p>';
								orderstatushtmlStr += '</li>';
								
							}
							
							
							if(data.payTime!=""){
								//已经付款,待发货状态
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titleb">付款</p>';
								orderstatushtmlStr += '<p>'+data.payTime+'</p>';
								orderstatushtmlStr += '</li>';
								
								$("#status_bar").removeClass("flow-goa").removeClass("flow-goc").addClass("flow-gob");
								
							}else if(data.statusId != '4' && data.paymentId =='2'){
								
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titleb">付款</p>';
								orderstatushtmlStr += '<p></p>';
								orderstatushtmlStr += '</li>';
							}
							
							
							
							if(data.deliverTime!=""){
								//已发货,等待收货
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titlec">发货</p>';
								orderstatushtmlStr += '<p>'+data.orderDate+'</p>';
								orderstatushtmlStr += '</li>';
								$("#status_bar").removeClass("flow-goa").removeClass("flow-gob").addClass("flow-goc");
								
							}else if(data.statusId != '4'){
								
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titlec">发货</p>';
								orderstatushtmlStr += '<p></p>';
								orderstatushtmlStr += '</li>';
								
							}
							
							

							if(data.finishTime!=""){
								//确认收货
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titled">确认收货</p>';
								orderstatushtmlStr += '<p>'+data.finishTime+'</p>';
								orderstatushtmlStr += '</li>';
								$("#status_bar").removeClass("flow-goa").removeClass("flow-gob").removeClass("flow-goc").addClass("flow-god");
								
							}else if(data.statusId != '4'){
																
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titled">确认收货</p>';
								orderstatushtmlStr += '<p></p>';
								orderstatushtmlStr += '</li>';
								
								$("#status_bar").removeClass("flow-god").addClass("flow-goc");
							}

							
							if(data.closeTime!=""){
								
								orderstatushtmlStr += '<li>';
								orderstatushtmlStr += '<p class="ldh-flow-titlec">交易关闭</p>';
								orderstatushtmlStr += '<p>'+data.closeTime+'</p>';
								orderstatushtmlStr += '</li>';
								
								$("#status_bar").removeClass("flow-goa").removeClass("flow-gob").addClass("flow-goc");
								
							}*/
							
							var statusStr="";
							$("#status_bar").removeClass("flow-goa").removeClass("flow-gob").removeClass("flow-goc").removeClass("flow-god");
						
							if(data.paymentId=="2"){
								//在线支付
								if(data.statusId == '1'){
									//待发货
									$("#status_bar").addClass("flow-gob");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">付款</p><p>'+data.payTime+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">发货</p><p></p></li>';
									statusStr+='<li><p class="ldh-flow-titled">确认收货</p><p></p></li>';
								
									
								}else if(data.statusId == '2'){
									//待收货
									$("#status_bar").addClass("flow-goc");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">付款</p><p>'+data.payTime+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">发货</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titled">确认收货</p><p></p></li>';
									
									
								
								}else if(data.statusId == '3'){
									//交易成功
									$("#status_bar").addClass("flow-god");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">付款</p><p>'+data.payTime+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">发货</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titled">确认收货</p><p>'+data.finishTime+'</p></li>';
								
									
								}else if(data.statusId == '4'){
									//交易关闭
									$("#status_bar").addClass("flow-god");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">交易关闭</p><p>'+data.closeTime+'</p></li>';
									
								}else if(data.statusId == '5'){
									//代付款
									$("#status_bar").addClass("flow-goa");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">付款</p><p></p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">发货</p><p></p></li>';
									statusStr+='<li><p class="ldh-flow-titled">确认收货</p><p></p></li>';
								
									
								}else if(data.statusId == '6'){
									//拒接收货
									$("#status_bar").addClass("flow-goc");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">付款</p><p>'+data.payTime+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">发货</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titled">确认收货</p><p></p></li>';
								
									
								}else if(data.statusId == '7'){
									//客服调解
									$("#status_bar").addClass("flow-goc");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">付款</p><p>'+data.payTime+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">发货</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titled">确认收货</p><p></p></li>';
									
								}
								
							}else{
								
								//货到付款
								if(data.statusId == '1'){
									//待发货
									$("#status_bar").addClass("flow-goa");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">发货</p><p></p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">确认收货</p><p></p></li>';
								
									
								}else if(data.statusId == '2'){
									//待收货
									$("#status_bar").addClass("flow-gob");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">发货</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">确认收货</p><p></p></li>';
									
									
								
								}else if(data.statusId == '3'){
									//交易成功
									$("#status_bar").addClass("flow-god");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">发货</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titlec">确认收货</p><p>'+data.finishTime+'</p></li>';
								
									
								}else if(data.statusId == '4'){
									//交易关闭
									$("#status_bar").addClass("flow-god");
									statusStr+='<li><p class="ldh-flow-titlea">提交订单</p><p>'+data.orderDate+'</p></li>';
									statusStr+='<li><p class="ldh-flow-titleb">交易关闭</p><p>'+data.closeTime+'</p></li>';
									
								}
								
							}
							
								
								
							$("#order_detail_status_bar").html(statusStr);
							
							//$("#order_detail_status_bar").html(orderstatushtmlStr);
				              
							//订单追踪
							var orderloghtmlStr="";
							for(var a=0;a<data.orderlog.length;a++){
								orderloghtmlStr +='<tr>';
								orderloghtmlStr +='<td>'+data.orderlog[a]["createTime"]+'</td>';
								orderloghtmlStr +='<td>'+data.orderlog[a]["memo"]+'</td>';
								orderloghtmlStr +='<td>'+data.orderlog[a]["operator"]+'</td></tr>';
							}
							$("#orderLogList").html(orderloghtmlStr);
							
							if(data.deliveryId=="1"){
								//收货信息
								$("#order_detail_shipName").html(data.shipName);
								$("#order_detail_shipMobile").html(data.shipMobile);
								$("#order_detail_shipAddress").html(data.shipAddress);
								$("#order_detail_shiptime").parent().show();
								$("#order_detail_zititime").parent().hide();
							}else{
								//自提信息
								$("#order_detail_zitiAddress").html(data.shopAddress);
								$("#order_detail_ziti_info").show();
								$("#order_detail_delivery_info").hide();
								$("#order_detail_shiptime").parent().hide();
								$("#order_detail_zititime").parent().show();
							}
							
							//卖家信息
							$("#order_detail_shopName").html(data.shopName);
							$("#order_detail_shopMobile").html(data.shopMobile);
							$("#order_detail_shopAddress").html(data.shopAddress);
							
							//订单信息
							$("#order_detail_orderId").html(data.orderId);
							$("#order_detail_status").html(data.statusName);
							$("#order_detail_payment").html(data.paymentName);
							$("#order_detail_shiptime").html(data.shipTime);
							$("#order_detail_zititime").html(data.shipTime);
							$("#order_detail_deliveryName").html(data.deliveryName);
							
							var htmlStr="";
							
							for(var i=0;i<data.items.length;i++){
								//'+data.items[i]["merchandiseName"]+'
											htmlStr += '<tr>';
											
											htmlStr += '<td>';
											htmlStr += '<table>';
											htmlStr += '<colgroup>';
											htmlStr += '<col width="16%">';
											htmlStr += '<col width="41%">';
											htmlStr += '</colgroup>';
											htmlStr += '<tbody>';
										
											htmlStr += '<tr>';
											
											var picDefault=data.items[i]["picDefault"];
											
											
											if(validate.isNull(picDefault)){
												
												picDefault = ctx+"/v1/img/default_234_220.png";

											}else{
												
												picDefault=fileOpenUrl+picDefault;

											}
											
											//htmlStr += '<td class="text-center"><div class="ldh-orderpic"><a class="pic" href="javascript:void(0)"><img src="'+fileOpenUrl+data.items[i]["picDefault"]+'" alt="查看宝贝详情"></a></div></td>';
											//htmlStr += '<td class="text-left"><a class="text" href="product.html" target="_blank">'+data.items[i]["merchandiseName"]+' </a></td>        ';
											htmlStr += '<td class="text-center"><div class="ldh-orderpic"><img src="'+picDefault+'" alt="查看宝贝详情"></div></td>';
											

											htmlStr += '<td class="text-left">'+data.items[i]["barcode"]+'</td>        ';
											htmlStr += '</tr>';
											htmlStr += '</tbody>';
											htmlStr += '</table>';
											htmlStr += '</td>';
											htmlStr += '<td class="text-left">'+data.items[i]["merchandiseName"]+'</td>        ';
											htmlStr += '<td>¥'+data.items[i]["price"]+'</td>';
											htmlStr += '<td>'+data.items[i]["nums"]+'</td>';
											htmlStr += '<td>¥'+data.items[i]["amount"]+'</td>';
											htmlStr += '</tr>';
							
							}
							
							if(data.deliveryAmount>0){
								
								$("#order_detail_merchandiseList").html(htmlStr+' <tr><td colspan="5" class="text-right ldh-myOrder-total"><span>配送费：'+Number(data.deliveryAmount).toFixed(2)+'元，</span><span>总计：</span><span>¥'+Number(data.totalAmount).toFixed(2)+'</span></td></tr>');
	
							}else{
								
								$("#order_detail_merchandiseList").html(htmlStr+' <tr><td colspan="5" class="text-right ldh-myOrder-total"><span>总计：</span><span>¥'+Number(data.totalAmount).toFixed(2)+'</span></td></tr>');

							}
							
							// 订单留言
							var ordermessagehtmlStr = "";
							
							for(var a=0;a<data.ordermessage.length;a++){
								
								
								ordermessagehtmlStr+='<li>';                 
								ordermessagehtmlStr+='<div class="article-post"> <span class="user-info"> '+data.ordermessage[a]["createName"]+'留言  /  日期：'+data.ordermessage[a]["createTime"]+' </span>';
								ordermessagehtmlStr+='<p><span class="main_color">'+data.ordermessage[a]["content"]+'</span></p>';
										
								
								
								if(data.ordermessage[a]["attach"]!=""){
									ordermessagehtmlStr+='<div class="user-thumb-pic">';
									var allUrl=data.ordermessage[a]["attach"].split(",");
									for (var j = 0; j < allUrl.length; j++) {
										if(allUrl[j]!=""){
											ordermessagehtmlStr += ' <a class="lightbox_trigger" href="'+fileOpenUrl+allUrl[j]+'"><img src="'+fileOpenUrl+allUrl[j]+'"></a>';
										}
									}
									ordermessagehtmlStr+='</div>';
								}
								
									
									
											
								ordermessagehtmlStr+='</div>';
								ordermessagehtmlStr+='</li>';
								
							}
							
							$("#messageList").html(ordermessagehtmlStr);
				
							
						}
						$("#order_detail_div").show();
						$("#order_detail_loading").hide();
						
							

			}))().start();
				
						
		
		
	};
	
	//拒绝收货
	exports.rejectReason=function(id,title,processCode,orderId){	
		  var btnleft="确定";
		  var btnright="取消";
		  var changepwd=
			  '<div id="'+id+'" class="alert_div">' +
				   '<div class="alert_div_con" style="min-height:0px;">' +
					   '<div class="close_alert close_alert_btn"></div>'+
					   '<div class="alert_header">'+title+'</div>'+
					   '<div class="alert_body clearfix">'+
					   		'<dl>'+
								'<dt id="reasonList">'+title+'原因</dt>'+
								/*'<dd><input type="radio" name="reject" class="radio" checked="checked" /><span class="click_span">商品有问题！</span></dd>'+
								'<dd><input type="radio" name="reject" class="radio" /><span class="click_span">送货太迟！</span></dd>'+
								'<dd><input type="radio" name="reject" class="radio" /><span class="click_span">商品损坏！</span></dd>'+*/
							'</dl>'+
							'<dl id="otherReasonDiv" style="display:none;">'+
								'<dt>其他原因</dt>'+
								'<dd><textarea class="textarea" id="reasonContent"></textarea></dd>'+
							'</dl>'+
							'<dl id="reasonImageDiv" style="display:none;">'+
								'<dt>上传证据</dt>'+
								'<dd><span id="upLoadReasonButton" ></span>&nbsp;<span id="upload_loading_upLoadReasonButton" style="display:none;"><img src="/shop/v1/img/upload_loading.gif" alt="头像"></span></dd>'+
								'<dd><div class="user-thumb-pic2"><ul id="reasonImageList"></ul></div></dd>'+
							'</dl>'+
					   '</div>'+
					   '<div class="ldh-waiting" id="order_process_loading" style="height:50px;display:none;" ></div>'+
					   '<div class="alert_footer">'+
					    '<button class="btn-green" type="button" onClick=$ldh_user.processOrder("'+id+'","'+processCode+'","'+orderId+'","是否确认'+title+'？") >确定</button> &nbsp'+
	               		'<button class="btn-main close_alert_btn" type="button">取消</button> &nbsp'+
					    '</div>'+
				   '</div>' +				   
			  '</div>'+'<div class="alert_div_bg"></div>';
		  $(changepwd).appendTo("body");
		  $("#"+id).find(".close_alert_btn").click(function(){
			  $("body").find(".alert_div_bg").remove();
			  $("#"+id).remove();		  		
		  });	  
		  
		  upload.ldh_upload("upLoadReasonButton","/order/reason","uploadReasonCallBack");
		  
			var params = {
					orderId:orderId,
					processCode:processCode
			};
			
			
			eval(
						Wind.compile("async", function() {

							var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/Order/getReasonList.do", params));
							
							
							if(data["code"]==1){		
								
								var htmlStr="";
								for (var i = 0; i < data["reasonList"].length; i++) {
									
									if(i==0){
										htmlStr += '<dd><input type="radio" name="reasons" class="radio" value="'+data["reasonList"][i]["reasonCode"]+'" checked="checked" /><span class="click_span">'+data["reasonList"][i]["reasonName"]+'</span></dd>';

									}else{
										
										htmlStr += '<dd><input type="radio" name="reasons" class="radio" value="'+data["reasonList"][i]["reasonCode"]+'" /><span class="click_span">'+data["reasonList"][i]["reasonName"]+'</span></dd>';

									}
								}
								
								$("#reasonList").after(htmlStr);
								
								$('.alert_body dl:eq(0) input:radio').click(function(e) {
									var reasonId=$(this).val();
									if(reasonId=="10"){
										$("#otherReasonDiv").css("display","block");
									}else{
										$("#otherReasonDiv").css("display","none");
									}
									
								});
								
								if(processCode=="6"||processCode=="4"){
									$("#reasonImageDiv").css("display","block");
								}else{
									$("#reasonImageDiv").css("display","none");
								}
								
							}
							
							
							

			}))().start();
		  
	};
	
	//订单处理
	exports.processOrder=function(id,processCode,orderId,tip){
		
		if(processCode=="支付"){
			window.location.href="";
		}
		
		var gnl=confirm(tip);

		if (gnl == true) {
			
			var reason=$('input[name="reasons"]:checked').val();
			var content = $("#reasonContent").val();
			var fileUrl="";//附件路径
			
			if($("#reasonImageDiv").css("display")=="block"){
				for (var i = 0; i <$("#reasonImageDiv li").length; i++) {
					
					fileUrl+=$("#reasonImageDiv li img").attr("source_src")+",";
				}
			}
			var params={
					"processCode" : processCode,
					"orderId" : orderId,
					"reason" : reason,
					"content" : content,
					"fileUrl" : fileUrl
			};
			
			$("#order_process_loading").show();
			
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/Order/processOrder.do", params));
						
						
						if(data["code"]==1){		
							
							if(data["code"]=="1"){
								
								$("body").find(".alert_div_bg").remove();
								
								$("#"+id).remove();
								
								exports.getOrderDetail(orderId);
								
							}else{
								
								alert("订单处理失败:"+data.message);
								
							}
							
							$("#order_process_loading").hide();
							
						}
						
						
						

					}))().start();
			
		};
	};
	
	//提醒商家发货
	exports.remindToShop=function(orderId,tip){
		
		var gnl=confirm(tip);

		if (gnl == true) {
			
				var params={
						"orderId" : orderId
				};
				
				eval(
						Wind.compile("async", function() {
	
							var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/Order/remindToShop.do", params));
							
							
							if(data["code"]==1){		
								
								alert("提醒商家发货成功");
								
							}else{
								
								alert("提醒商家发货失败");
							}
	
				}))().start();
		}
	};

	//去付款
	exports.goPay=function(orderId,totalAmount){
		
		get2post(ctx+"/v1/pages/order/pay.jsp?order="+orderId+"&orderIds="+orderId+"&totalMoney="+Number(totalAmount).toFixed(2));
		
	};
	
	//上传理由回调函数
	uploadReasonCallBack=function(dataObj){
		
		var dataPath = "";
		if(dataObj.code == "1"){
			for(var i=0;i<dataObj.files.length;i++){
				if(dataObj.files[i].repCode=="1"){
					dataPath = dataObj.files[i].path;
					/*$("#ucenter_iconUrl").val(dataPath);
					$("#ucenter_iconUrl").attr("src", fileOpenUrl + dataPath);
					$("#div_myinfo_tip").show();
					$("#myinfo_tip").html("上传头像成功,请保存")*/;
				
					//$("#iconUrlInput").val(dataPath);
					$("#reasonImageList").append('<li><a class="lightboxTrigger" href="'+ctx+'/v1/img/lit_03.png"><img src="'+fileOpenUrl + dataPath+'" source_src="'+dataPath+'"></a><p onclick="$ldh_user.deleteReasonPic(this)">删除</p></li>');
					
				}else{
					
				}
			}
			
			
		}else{
			
			//上传失败
			
		}
		
		$("#upload_loading_upLoadReasonButton").hide();
	//	task("#div_myinfo_tip").start();
		
	};
	
	//删除理由图片
	exports.deleteReasonPic=function(obj){
		
		$(obj).parent().remove();
	};
	
	
	//设置收藏列表页码
	exports.setFavorCurrentPage=function(favorCurrentPage){
		
		this.favorCurrentPage=favorCurrentPage;
		
	};
	
	//获取收藏列表页码
	exports.getFavorCurrentPage=function(){
		
		return this.favorCurrentPage==null?1:this.favorCurrentPage;
		
	};
	
	//收藏商家列表
	exports.getMyFavorShop=function(){
		
		//history.addHis(this,arguments);
		
		$(".ldh-myCenterR").hide();
		

		$("#ldh-myFavorList").show();
		
		
		$("#myfavor-no-data-tip").hide();
		
		$(".ldh-myCenter-btm li a").css("color","#9a8072");

		
		$(".ldh-index-clobiz").css("color","#ed5d3a");
		
		
		
		
		var params = {
				currentPage:exports.getFavorCurrentPage(),
				pageSize :pageSize
		};
		
		base.showLoading("#shopList","",true);
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/MyShop/getMyShops.do", params));
						
						
						if(data["code"]==1){
		
							var htmlStr="";
							
						/*	if(data["rflag"]==1){
								
								htmlStr='<li>找不到符合条件的商家.下面为你推荐优质商家.你也可以马上"<font color="#ed5d3a">开店进驻</font>"哦.</li>';
							}*/

							for (var i = 0; i < data["shops"].length; i++) {
							
							//var distance=data["shops"][i]["distance"];
							
							var introduce=data["shops"][i]["introduce"];
							
							var minAmount = data["shops"][i]["minAmount"];
							
							var businessStatus = data["shops"][i]["businessStatus"];

							var score=(data["shops"][i]["score"]/5)*100;
							
							var businessHours=data["shops"][i]["businessHours"];
							
							var range= data["shops"][i]["range"];
							
							if(validate.isNull(introduce))
								introduce="暂无";
							
							if(validate.isNull(businessHours))
								businessHours="全天";
							
					/*		if(distance.indexOf(">")>=0){
								
								distance=distance+"km";
								
							}else if(distance<1){
								
								distance=(distance*1000)+"m";
								
							}else{
								
								distance="约"+parseInt(distance)+"km";
							}*/
							
							if(minAmount=="" || minAmount=="0"){
								minAmount="不限";
							}else{
								minAmount=minAmount+"元";
							}

							if(range=="" || range=="0"){
								range="不限";
							}else{
								range=range+"米";
							}
										htmlStr += '<li style="cursor:default">';
										
										if(data["shops"][i]["logoUrl"]!="" && data["shops"][i]["logoUrl"].indexOf(".")>0){
											htmlStr += '<div style="cursor:pointer" class="ldh-storeList-pic"  onclick=$ldh_base.jumpToShopIndex("'+data["shops"][i]["shopId"]+'")><img src="'+fileOpenUrl+data["shops"][i]["logoUrl"]+'"></div>';
										}else{
											htmlStr += '<div style="cursor:pointer" class="ldh-storeList-pic"  onclick=$ldh_base.jumpToShopIndex("'+data["shops"][i]["shopId"]+'")><img src="'+ctx+'/v1/img/category_f.png"></div>';
										}
										htmlStr += '<div class="ldh-storeList-info">';
										htmlStr += '<div class="ldh-storeList-infoT">';
										htmlStr += '<div class="fl-left">';
										htmlStr += '<h3 style="cursor:pointer" class="fl-left"  onclick=$ldh_base.jumpToShopIndex("'+data["shops"][i]["shopId"]+'")>'+data["shops"][i]["shopName"]+'</h3>';
										htmlStr += '<p class="fl-left">'+base.getSpeHtml(data["shops"][i]["speId"])+'</p>';
										htmlStr += '<div class="ldh-storeList-hideBox">';
										htmlStr += '<dl>';
										htmlStr += '<dt><h3>'+data["shops"][i]["shopName"]+'</h3></dt>';
										htmlStr += base.getSpeListHtml(data["shops"][i]["speId"]);
										htmlStr += '</dl>';
										htmlStr += '<div>';
										htmlStr += '<p>商家公告</p>';
										htmlStr += '<span>'+introduce+'</span>';
										htmlStr += '</div>';
										htmlStr += '</div>';
										htmlStr += '</div>';
										//htmlStr += '<div class="fl-right"><span>距离'+distance+'</span></div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-storeList-infoM">';
										htmlStr += '<div class="fl-left"><span>起送金额(元)：<b class="money">'+minAmount+'</b></span><span>配送范围：<b class="free">'+range+'</b></span><span>营业时间：<b class="time">'+businessHours+'</b></span></div>';
										htmlStr += '<div class="fl-right"><span class="ldh-store-star">';
										htmlStr += '<em style="width:'+score+'%"></em>';
										htmlStr += '</span></div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-storeList-infoB">';
										htmlStr += '<div class="fl-left"><span>店铺地址：'+data["shops"][i]["address"]+'</span></div>';
										if(businessStatus=="1"){
											htmlStr += '<div class="fl-right"><span class="ldh-store-state">营业中</span></div>';
										}else{
											
											htmlStr += '<div class="fl-right"><span class="ldh-store-state off">休息中</span></div>';
										}
										
										htmlStr += '</div>';
										htmlStr += '</div>';
										htmlStr += '</li>';
										
										
							}
							
							if(validate.isNull(htmlStr)){
								
								$("#myfavor-no-data-tip").show();
								
								$('#myfavor-footPage').html("");
								
							}else{
								
							
								$("#myfavor-no-data-tip").hide();
								
								$("#shopList").html(htmlStr);
								
								 $('#myfavor-footPage').ldh_pagination_shoplist(data["pageSize"],data["currentPage"],data["totals"],data["pages"],{  
									 
									 changePageCallback:function(pageSize,page){  
										
										 exports.setFavorCurrentPage(page);
										 
										 exports.getMyFavorShop();
									 },
									 changePageSizeCallBack:function(pageSize){
									 } 
						         }); 
							}

						}
						
						base.cancelLoading("#shopList");
						
						
					}))().start();
			
	};
	
	//查询我的个人信息
	exports.getMyInfo=function(){
		
		$("#div_myinfo_tip").hide();
		
		$(".ldh-myCenterR").hide();
		
		$("#ldh-myInfo").show();
		
		$(".ldh-myCenter-btm li a").css("color","#9a8072");

		$(".ldh-index-user").css("color","#ed5d3a");
		
		var params = {
			userId:$("#session_userid").val()
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/User/getUserInfo.do", params));
						
						//$("#myorder-ldh-waiting").hide();
						
						if(!base.validateLoginStatus(data)){
		
							return;
						}
						
						
						if(data["code"]==1){
							
							$("#ucenter_userName").html(data["RsUser"]["userName"]);
							$("#ucenter_realName").val(data["RsUser"]["realName"]);
							$("#ucenter_email").val(data["RsUser"]["email"]);
							if(!validate.isNull(data["RsUser"]["iconUrl"])){
								
								$("#ucenter_iconUrl").attr("src", fileOpenUrl + data["RsUser"]["iconUrl"]);
							}
							
						/*	$("#address").val(data["RsUser"]["address"]);
							$("#show_userName strong").text(data["RsUser"]["userName"]);
							$("#mobile").val(data["RsUser"]["mobile"]);
							$("#realName").val(data["RsUser"]["realName"]);
							var sexInfo = data["RsUser"]["sex"];
							$("input[name='sex'][value='" + sexInfo + "']").attr("checked", true);
							$("#birthday").val(data["RsUser"]["birthday"]);
							$("#phoneNumber").val(data["RsUser"]["phoneNumber"]);
							$("#zipcode").val(data["RsUser"]["zipcode"]);*/
							
 
						}else if(data["code"]=="-10001"){
							
							alert(data["message"]);
							
						}
						
						
		}))().start();
		
	};
	
	//更新个人信息
	exports.updateUserInfo=function(){
		
		var email=$("#ucenter_email").val();
		

		$("#div_myinfo_tip").show();
		
		if(!validate.isNull(email)){
			
			if(!validate.isEmail(email)){
				
				
				$("#myinfo_tip").html("邮箱格式不正确");
								
				return;
			}
			
			
		}
		
		$("#myinfo_tip").html("正在保存...");
		
		var params={
				userName:$("#ucenter_userName").text(),
				realName:$("#ucenter_realName").val(),
				email:email,
				iconUrl:$("#ucenter_iconUrl").val()
				
		};
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/User/updateUserInfo.do", params));
					
					$("#div_myinfo_tip").show();
					
					if(data["code"]==1){
						
						
						
						$("#myinfo_tip").html("保存成功");
						
						$("#userIndex_iconUrl,#iconUrl").attr("src",fileOpenUrl+$("#ucenter_iconUrl").val());
						
						
						
					}else{
						
						
						$("#myinfo_tip").html(data["message"]);
						
					}
					task("#div_myinfo_tip").start();
					
					
				}))().start();
	};
	
	var boundx,boundy;
	//上传头像回调函数
	uploadHeadImageCallBack=function(dataObj){
		
		var dataPath = "";
		if(dataObj.code == "1"){
			for(var i=0;i<dataObj.files.length;i++){
				if(dataObj.files[i].repCode=="1"){
					dataPath = dataObj.files[i].path;
					//$("#ucenter_iconUrl").val(dataPath);
					//$("#ucenter_iconUrl").attr("src", fileOpenUrl + dataPath);
					
					$("#upLoadFileButton").appendTo($(".ldh-mypic-btn"));
					$("#ucenter_preview_iconUrl_div").html('<img id="ucenter_preview_iconUrl" src="'+fileOpenSourceUrl + dataPath+'" alt="头像" />');
					$("#preview_iconUrl_90").attr("src", fileOpenSourceUrl + dataPath);
					$("#preview_iconUrl_50").attr("src", fileOpenSourceUrl + dataPath);
					$("#preview_iconUrl_30").attr("src", fileOpenSourceUrl + dataPath);
					 // Invoke Jcrop in typical fashion
				      $('#ucenter_preview_iconUrl').Jcrop({
				    	onChange: updatePreview,
				  		onSelect: updatePreview,
				  		aspectRatio: 1,
				  		allowSelect:true
				      },function(){

				    	var bounds = this.getBounds();
				  		boundx = bounds[0];
				  		boundy = bounds[1];
				  	    //this.animateTo([100,100,100,100]);
				  	   // $('#preview-pane_90,#preview-pane_50,#preview-pane_30').appendTo(this.ui.holder);
				  	  
				      });
				      
					//$("#div_myinfo_tip").show();
					
					//$("#myinfo_tip").html("上传头像成功,请保存");
				
					//$("#iconUrlInput").val(dataPath);
				}else{
					
				}
			}
			
			
		}else{
			
			//上传失败
			//$("#myinfo_tip").html("上传头像失败");
		}
		
		$("#upload_loading_upLoadFileButton").hide();
		
		//task("#div_myinfo_tip").start();
		
	};

	function updatePreview(c){
		if (parseInt(c.w) > 0) {
			
			//c.x+","+c.y+","+c.w+","+c.h;	
			$("#x_upLoadFileButton").val(c.x);
			$("#y_upLoadFileButton").val(c.y);
			$("#width_upLoadFileButton").val(c.w);
			$("#height_upLoadFileButton").val(c.h);
			
			var rx = 90 / c.w;
			var ry = 90 / c.h;
			$('#preview_iconUrl_90').css({
				width: Math.round(rx * boundx) + 'px',
				height: Math.round(ry * boundy) + 'px',
				marginLeft: '-' + Math.round(rx * c.x) + 'px',
				marginTop: '-' + Math.round(ry * c.y) + 'px'
			});
			rx = 50 / c.w;
			ry = 50 / c.h;
			$('#preview_iconUrl_50').css({
				width: Math.round(rx * boundx) + 'px',
				height: Math.round(ry * boundy) + 'px',
				marginLeft: '-' + Math.round(rx * c.x) + 'px',
				marginTop: '-' + Math.round(ry * c.y) + 'px'
			});
			rx = 30 / c.w;
			ry = 30 / c.h;
			$('#preview_iconUrl_30').css({
				width: Math.round(rx * boundx) + 'px',
				height: Math.round(ry * boundy) + 'px',
				marginLeft: '-' + Math.round(rx * c.x) + 'px',
				marginTop: '-' + Math.round(ry * c.y) + 'px'
			});
		}
	};
	
	//账户安全
	exports.setAccountSafe=function(){
		
		$("#div_account_safe_tip").hide();
		
		$("#div_account_safe_mobile_tip").hide();
		
		$(".ldh-myCenterR").hide();
		
		$("#ldh-account-safe").show();
		
		$(".ldh-myCenter-btm li a").css("color","#9a8072");

		$(".ldh-index-safety").css("color","#ed5d3a");
		
	};
	
	//重设登录密码
	exports.resetLoginPwd=function(){
		
			var old_password=$("#ucenter_old_password").val();
			
			var new_password=$("#ucenter_new_password").val();
			
			var r_new_password=$("#ucenter_r_new_password").val();
			
			$("#div_account_safe_tip").show();
			
			if(validate.isNull(old_password)){
				
				$("#div_account_safe_tip span").html("当前密码不能为空");
				
				return;
			}

			if(!validate.isLoginPassword(new_password)){
				
				$("#div_account_safe_tip span").html("新密码为6-20位数字，字母，符号组合，请重新输入");
				
				return;
			}
			
			if(r_new_password!=new_password){
				
				$("#div_account_safe_tip span").html("两次密码不一致");
				
				return;
			}
		
			var params={
				oldPwd:MD5(old_password),
				newPwd:MD5(new_password)
					
			};
			
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/AccountSafe/resetLoginPwd.do", params));
						
						if(data["code"]==1){
							
							$("#div_account_safe_tip span").html("重设密码成功");
							
						}else{
							$("#div_account_safe_tip span").html(data["message"]);
							
						}
						
						$("#ucenter_old_password").val("");
						
						$("#ucenter_new_password").val("");
						
						$("#ucenter_r_new_password").val("");
						
						task("#div_account_safe_tip").start();
						
						
					}))().start();
	};
	
	
	//验证手机号
	exports.validateMobile=function(btnId){
		
		var mobile = $("#ucenter_new_mobile").val();
		
		$("#div_account_safe_mobile_tip").show();
		
		if(!validate.isMobile(mobile)){
			
			$("#div_account_safe_mobile_tip span").html("请填写正确的手机号码");
			
			return;
		}
		
		$(btnId).attr("disabled", "disabled");

		//base.showLoading(btnId,20,true);
		
		var params={
				
				"mobile":mobile
			};
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/AccountSafe/validateMobile.do", params));
			
			if(data.code == "1"){
				//未注册,发送验证码
				$("#div_account_safe_mobile_tip").hide();
				
				sendMessage(mobile,btnId);
			}else{
				
				$("#div_account_safe_mobile_tip span").html(data.message);
				
				$(btnId).val("免费获取验证码");
				
				//如果该手机已注册,则可以马上重新验证
				$(btnId).attr("disabled", false);
			}

		}))().start();
		
	};
	
	
	//发送短信验证码
	function sendMessage(mobile,btnId){
		
		var params={
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/AccountSafe/sendValidateCode.do", params));

			if(data.code == "1"){
				
				$("#div_account_safe_mobile_tip").show();
				
				$("#div_account_safe_mobile_tip span").html("验证码已发送,请注意查收");
				
				task("#div_account_safe_mobile_tip").start();
				
				task_mobile(btnId).start();
				
				
				
			}else{
				
				//如果获取验证码失败,则可以马上重新获取
				$(btnId).attr("disabled", false);
				
				$(btnId).val("免费获取验证码");
				
				$("#div_account_safe_mobile_tip span").html(data.message);
			
			}

		}))().start();
	}
	
	//绑定手机
	exports.setMobile=function(){
		
		var params={
				"mobile":$("#ucenter_new_mobile").val(),
				"validateCode":$("#ucenter_validate_code").val()
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/AccountSafe/setMobile.do", params));

			$("#div_account_safe_mobile_tip").show();
			
			if(data.code == "1"){
				
				$("#div_account_safe_mobile_tip span").html("绑定成功");
				
				$("#ucenter_new_mobile").val("");
				
				$("#ucenter_validate_code").val("");
				
				
			}else{
				
				$("#div_account_safe_mobile_tip span").html(data.message);
			
			}
			
			task("#div_account_safe_mobile_tip").start();
			
		}))().start();
		
	};
	
	//收货地址
	exports.setShippingAddress=function(){
		
		//history.addHis(this,arguments);
		
		
		
		$(".ldh-myAdress-edit").hide();
		
		$(".ldh-myCenterR").hide();
		
		$("#ldh-shipping-address").show();
		
		$(".ldh-myCenter-btm li a").css("color","#9a8072");

		$(".ldh-index-adress").css("color","#ed5d3a");
		
		exports.getMyAddressList();
		
	};
	
	//查询收货地址列表
	exports.getMyAddressList=function(){
		
		$("#myAddressList").html('<tr><td><div class="ldh-waiting"></div></td></tr>');
		
		var params={
				userId:$("#session_userid").val(),
				currentPage:1,
				pageSize:10
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Address/addressList.do", params));

			if(data.code == "1"){
				
				var htmlStr="";
				
				for(var i=0;i<data["addressList"].length;i++){
					

						htmlStr += '<tr>';
						if(data["addressList"][i]["def"]=="1"){

							htmlStr += '<td><input type="radio" name="radio.adress" checked="checked" /></td>';
						}else{

							htmlStr += '<td><input type="radio" name="radio.adress" /></td>';
						}
						htmlStr += '<td>'+data["addressList"][i]["shipName"]+'</td>';
						htmlStr += '<td>'+data["addressList"][i]["memo"]+'</td>';
						htmlStr += '<td>'+data["addressList"][i]["shipMobile"]+'</td>';
						htmlStr += '<td class="text-right"><p class="ldh-myAdress-operate"><a href=javascript:$ldh_user.loadAddress("'+data["addressList"][i]["addressId"]+'")>编辑</a>|<a href=javascript:$ldh_user.deleteAddress("'+data["addressList"][i]["addressId"]+'")>删除</a></p></td>';
						htmlStr += '</tr>';
				}
				
				
				$("#myAddressList").html(htmlStr);
			}else{
				
			}
		}))().start();
		
	};
	
	//打开添加收货地址
	exports.openEditAddress=function(){
		
		$(".ldh-myAdress-edit").show();	
		
		exports.findAllProvince();
		
	};
	
	//保存收货地址
	exports.saveAddress=function(type){
		
		var provinceId=exports.getProvinceId();
		var cityId=exports.getCityId();
		var regionId=exports.getRegionId();
		var ship_address=$("#ucenter_ship_address").val();
		var ship_mobile=$("#ucenter_ship_mobile").val();
		var shipName=$("#ucenter_shipName").val();
		
		$("#div_address_tip").show();
		
		if(validate.isNull(shipName)){
		   $("#div_address_tip span").html("收货人不能为空");
		   return;
		}
		if(validate.isNull(provinceId)){
			$("#div_address_tip span").html("请选择省份");
		   return;
		}
		if(validate.isNull(cityId)){
			$("#div_address_tip span").html("请选择城市");
		   return;
		}
		if(validate.isNull(regionId)){
			$("#div_address_tip span").html("请选择区域");
		   return;
		}
		if(validate.isNull(ship_address)){
		   $("#div_address_tip span").html("请填写详细地址");
		   return;
		}
		if(!validate.isMobile(ship_mobile)){
			   $("#div_address_tip span").html("请填写正确的手机号码");
			   return;
			}
		
		var def = 0;
		
		if($("#ucenter_def").is(":checked")){
			def = 1;
		}
		
		var memo=$("#province_name").text()+" "+$("#city_name").text()+" "+$("#region_name").text()+" "+ship_address;
		
		var params={
				"userId":$("#session_userid").val(),
				"provinceId":provinceId,
				"cityId":cityId,
				"regionId":regionId,
				"memo":memo,
				"shipName":shipName,
				"shipMobile":ship_mobile,
				"street":ship_address,
				"def":def
			};
		
		if(type=="1"){
			params["addressId"]=exports.getAddressId();
		}

		$("#div_address_tip span").html("正在提交,请稍候...");

		eval(Wind.compile("async", function() {
			var data;
			if(type=="0"){
				
				data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Address/saveAddress.do", params));

			}else{
				
				data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Address/updateAddress.do", params));

			}
			
			$("#div_address_tip").show();
			 
			if(data.code == "1"){
				
				 $(".ldh-myAdress-edit").hide();
				 
				  if(type=="1"){
					  
					 $("#div_address_tip span").html("编辑成功");
					  
					 $(".ldh-myAdress-new button").html("添加新地址");
						
					 $("#btn_edit_address").attr("onclick","$ldh_user.saveAddress(0)");
					 
				  }else{
					  
					  $("#div_address_tip span").html("添加成功");
				  }
				  
					exports.setProvinceId("","请选择");
					exports.setCityId("","请选择");
					exports.setRegionId("","请选择");
					$("#ucenter_ship_address").val("");
					$("#ucenter_ship_mobile").val("");
					$("#ucenter_shipName").val("");
					
				 exports.getMyAddressList();
				
			}else{
				
				
				 $("#div_address_tip span").html(data.message);
			}
			
			task("#div_address_tip").start();
			
			
		}))().start();
		
	};
	
	//删除收货地址
	exports.deleteAddress=function(addressId){
		
		var params={
			"addressId":addressId
		};
		
		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Address/delAddress.do", params));
			
			if(data.code == "1"){
				
				 exports.getMyAddressList();
				
			}else{
				
				
			}
			
			
		}))().start();
	};
	
	//加载收货地址,用户编辑
	exports.loadAddress=function(addressId){
		
		exports.setAddressId(addressId);
		
		exports.openEditAddress();
		
		$(".ldh-myAdress-new button").html("编辑收货地址");
		
		$("#btn_edit_address").attr("onclick","$ldh_user.saveAddress(1)");
		
		$("#div_address_loading").show();
		
		$("#div_address_tip").hide();
		
		var params={
				"addressId":addressId
			};
			
			eval(Wind.compile("async", function() {

				var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Address/loadAddress.do", params));
				
				if(data.code == "1"){
					
					exports.setProvinceId(data["address"]["provinceId"]);
					exports.setCityId(data["address"]["cityId"]);
					exports.setRegionId(data["address"]["regionId"]);
					$("#ucenter_ship_address").val(data["address"]["street"]);
					$("#ucenter_ship_mobile").val(data["address"]["shipMobile"]);
					$("#ucenter_shipName").val(data["address"]["shipName"]);
					$("#province_name").html(data["address"]["provinceName"]);
					$("#city_name").html(data["address"]["cityName"]);
					$("#region_name").html(data["address"]["regionName"]);
					
					
				}else{
					
					
				}
				$("#div_address_loading").hide();
				
			}))().start();
		
	};
	
	/**
	 * 查询所有省份
	 */
	exports.findAllProvince=function(){
		
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx
							+ "/shopweb/SysParam/findAllProvince.do", ""));
					
					findAllProvinceCallBack(data);

				}))().start();
		
	};
	
	/**
	 * 查询所有省份_回调函数
	 */
	function findAllProvinceCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data.length;i++){
			
			htmlStr+='<li><a href=javascript:$ldh_user.setProvinceId("'+data[i].PROVINCE_ID+'","'+data[i].PROVINCE_NAME+'")>'+data[i].PROVINCE_NAME+'</a></li>';
		}
		
		$("#provinceList").html('<li><a href=javascript:$ldh_user.setProvinceId("","请选择")>请选择</a></li>'+htmlStr);
	}
	
	/**
	 * 根据省份查询城市
	 */
	function findCityByProvince(provinceId){
		
		var params={
			provinceId:provinceId
		};
		
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx
							+ "/shopweb/SysParam/findCityByProvince.do",params));
					
					findCityByProvinceCallBack(data);

				}))().start();
	}
	
	/**
	 * 根据省份查询城市
	 */
	function findCityByProvinceCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data.length;i++){
						
			htmlStr+='<li><a href=javascript:$ldh_user.setCityId("'+data[i].CITY_ID+'","'+data[i].CITY_NAME+'")>'+data[i].CITY_NAME+'</a></li>';
		}
		
		$("#cityList").html('<li><a href=javascript:$ldh_user.setCityId("","请选择")>请选择</a></li>'+htmlStr);
	}
	
	/**
	 * 根据城市查询区域
	 */
	function findRegionByCity(cityId){
		
		var params={
				cityId:cityId
			};
		
		eval(Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx
							+ "/shopweb/SysParam/findRegionByCity.do",params));
					
					findRegionByCityCallBack(data);

				}))().start();
	}
	
	/**
	 * 根据城市查询区域_回调函数
	 */
	function findRegionByCityCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data.length;i++){
			
			htmlStr+='<li><a href=javascript:$ldh_user.setRegionId("'+data[i].REGION_ID+'","'+data[i].REGION_NAME+'")>'+data[i].REGION_NAME+'</a></li>';

		}
		
		$("#regionList").html('<li><a href=javascript:$ldh_user.setRegionId("","请选择")>请选择</a></li>'+htmlStr);
		
	}
	
	exports.setAddressId=function(addressId){
		
		this.addressId=addressId;
	
	};
	
	exports.getAddressId=function(){
		
		return this.addressId==null?"":this.addressId;
		
	};
	
	exports.setProvinceId=function(provinceId,provinceName){
		
		this.provinceId=provinceId;
		
		$("#province_name").html(provinceName);
		
		$("#provinceList").parent().removeClass("open");
		
		exports.setCityId("","请选择");
		
		exports.setRegionId("","请选择");
		
		if(provinceId=="")
			return;
		
		findCityByProvince(provinceId);
		
	};
	
	exports.getProvinceId=function(){
		
		return this.provinceId==null?"":this.provinceId;
		
	};
	
	exports.setCityId=function(cityId,cityName){
		
		this.cityId=cityId;
		
		$("#city_name").html(cityName);
		
		$("#cityList").parent().removeClass("open");
		
		exports.setRegionId("","请选择");
		
		if(cityId=="")
			return;
		
		findRegionByCity(cityId);
		
	};
	
	exports.getCityId=function(){
		
		return this.cityId==null?"":this.cityId;
		
	};
	
	
	exports.setRegionId=function(regionId,regionName){
		
		this.regionId=regionId;
		
		$("#region_name").html(regionName);
		
		$("#regionList").parent().removeClass("open");
		
		
		if(regionId=="")
			return;
		
	};
	
	exports.getRegionId=function(){
		
		return this.regionId==null?"":this.regionId;
		
	};
	
	
	//定时提示信息
	var tips_task = eval(Wind.compile("async", function (divId) {
		
	    $await(Wind.Async.sleep(2000));
	   
	    $(divId).hide();
	    
	    
	}));
	
	var task = eval(Wind.compile("async", function (divId) {
	    $await(tips_task(divId));
	}));
	
	//验证码倒计时
	var wait = 90;
	
	var tips_task_mobile = eval(Wind.compile("async", function (btnId) {
		wait--;
	    $await(Wind.Async.sleep(1000));
	    if(wait==0){
	    	//倒计时完成,发送验证码按钮生效
	    	$(btnId).attr("disabled", false);
	    	$(btnId).val("免费获取验证码");
	    	
	    }else{
	    	
	    	$(btnId).val(wait + "秒后重新获取");
	    }
	    
	}));
	
	var task_mobile = eval(Wind.compile("async", function (btnId) {
	    $await(tips_task_mobile(btnId));
	    if(wait>0){
	    	task_mobile(btnId).start();
	    }else{
	    	wait=90;
	    }
	}));
	
});

